package com.questionnaires.controller;

import com.questionnaires.model.User;
import com.questionnaires.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Ioana
 * Date: 1/16/12
 * Time: 9:30 PM
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/showForm")
    public String showUserCreateForm(Map<String, Object> modelMap) {
        
        User user = new User();
        modelMap.put("user", user);
        return "user";
    }
    
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String addUser(@ModelAttribute("user")
          User user, BindingResult result) {

        userService.addUser(user);
        return "redirect:/index";
    }

}
